package com.du.stutestsys.controller.TeacherManage;

import com.du.stutestsys.controller.BaseControler;
import com.du.stutestsys.entity.Chapter;
import com.du.stutestsys.entity.SysUser;
import com.du.stutestsys.service.TeacherManage.ChapterService;
import com.du.stutestsys.util.DuUtil;
import com.du.stutestsys.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Controller
public class ChapterController extends BaseControler {
    @Autowired
    ChapterService chapterService;

    @GetMapping("TeacherManage/selectChapter")
    public String selectChapter(@RequestBody Chapter chapter){
        PageUtil pageUtil = DuUtil.setPageUtil(chapter, 0, 10);
        List<Chapter> chapters = chapterService.selectChapter(chapter, pageUtil);
        return DuUtil.success(chapters,chapters+"",pageUtil).toJSONString();
    }
    //新增
    @PostMapping("TeacherManage/addChapter")
    public String addChapter(@RequestBody Chapter chapter){
        return DuUtil.success(chapterService.addChapter(chapter)).toJSONString();
    }


    //批量删除章节
    @PostMapping("TeacherManage/deleteChapter")
    public String deleteChapter(@RequestBody List<Long> ids){
        return DuUtil.success(chapterService.deleteChapter(ids)).toJSONString();
    }

    //修改章节名or描述
    @PostMapping("TeacherManage/updateChapter")
    public String updateChapter(@RequestBody Chapter chapter){
        return DuUtil.success(chapterService.updateChapter(chapter)).toJSONString();
    }
}
